package com.zhou.learn.controller;

import com.zhou.learn.dao.SpringDataJpaRepository;
import com.zhou.learn.entity.SysUser;
import com.zhou.learn.service.ISpringDataJpaervice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SpringDataJpaController {
    @Autowired
    SpringDataJpaRepository springDataJpaRepository;
    @Autowired
    ISpringDataJpaervice userService;

    @GetMapping("/user/{id}")
    public SysUser query(@PathVariable("id") int id){
        SysUser user = springDataJpaRepository.findById(id).get();
        return user;
    }

    @GetMapping("/user")
    public SysUser insert(SysUser user){
        springDataJpaRepository.save(user);
        return user;
    }

    @GetMapping("/user2")
    public SysUser addUser(SysUser user){
        userService.addUser(user);
        return user;
    }
}
